#include "compress.h"

#include <sstream>

#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>


namespace compress
{

void gzip(std::istream &in, std::ostream &out) {
    namespace b = boost::iostreams;
    b::filtering_streambuf<b::input> buff;
    buff.push(b::gzip_compressor(b::gzip_params(b::gzip::best_compression)));
    buff.push(in);
    b::copy(buff, out);
}

void gzip(std::string &data) {
    std::istringstream in(data);
    std::ostringstream out;
    gzip(in, out);
    data = out.str();
}

} // namespace compress
